package edu.biwu.cookie;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

/**
 * 利用 jakarta.servlet.http.Cookie 类构造Cookie,数据格式类似一种map结构(key=value)
 *      public Cookie(String name, String value):创建name=value的cookie
 * 利用 response 中的方法将cookie响应给浏览器
 *      void addCookie(Cookie var1):将cookie响应给浏览器
 */
@WebServlet("/cookie/send")
public class CookieSend extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Cookie cookie = new Cookie("id", "123");
        response.addCookie(cookie);
        response.addCookie(new Cookie("name","zhangsan"));
        response.addCookie(new Cookie("id","14"));//同一个name属性的value值会产生覆盖
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
